import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'

import { getById } from '../../services/type'
// 异步方法
export const fetchType = createAsyncThunk('snap/fetchSnap', async (id) => {
    let { data } = await getById(id);
    // console.log("sliceSnap:", data);
    return data;
})


const typeSlice = createSlice({
    name: "type",
    initialState: {
        // 初始值
        types: {},
        isModalVisible: false
    },
    reducers: {

        setIsModalVisible(state, action) {
            state.isModalVisible = action.payload
        }
    },
    // 扩展reducers

    extraReducers(builder) {
        builder.addCase(fetchType.fulfilled, (state, action) => {
            state.types = action.payload;
            // console.log("dsadsaf", state.types);
        })
    }

})

export const { setIsModalVisible } = typeSlice.actions;
export default typeSlice.reducer;
